// @import
import UserData from "../../data/UserData";
import { g_oCmdHandlerMap } from "../ICmdHandler";
// @import
import mod_gameMsgProtocol = require("../../msg/mod_gameMsgProtocol");

/**
 * 用户登录结果处理器
 */
export default class UserLoginResultHandler {
    /**
     * 处理结果
     * 
     * @param oResult 结果
     * @returns
     */
    handle(oResult: mod_gameMsgProtocol.msg.UserLoginResult): void {
        if (null == oResult) {
            return;
        }

        if (null == oResult.userId ||
            oResult.userId <= 0) {
            return;
        }

        UserData.initMyData(oResult.userId);

        if (null == oResult.heroAvatar || 
            oResult.heroAvatar.length <= 0) {
            cc.director.loadScene("SelectHeroScene");
            return;
        }

        UserData.getMyData()._strHeroAvatar = oResult.heroAvatar;
        cc.director.loadScene("GameScene");
    }
}

// @autoExec
(function() {
    console.log("注册 -- UserLoginResultHandler");
    g_oCmdHandlerMap.set(
        mod_gameMsgProtocol.msg.MsgCode.USER_LOGIN_RESULT, 
        new UserLoginResultHandler()
    );
})();
